﻿using System;
using System.Data;
using System.Web.UI.WebControls;
using System.Xml;
using MyWeb.Business;

namespace MyWeb.Controls
{
    public partial class u_right : System.Web.UI.UserControl
    {
        private string _lang = "";
        #region Page Load
        protected void Page_Load(object sender, EventArgs e)
        {
            _lang = Session["Lang"].ToString() != "" ? Session["Lang"].ToString() : "vi";
            if (!IsPostBack)
            {
                ShowSupport();
                ShowFacePage();
                Vitri();
                BindDropDownList();
                divWeather.InnerHtml = GetWeather("HaNoi");
                LoadCard();
                //ShowTuyenDung();
            }
        }
        #endregion

        #region Support
        private void ShowSupport()
        {
            var s = "<div class=\"boxRightTittle\">";
            s += "<div class=\"boxMenu\"><strong>Tư vấn và hỗ trợ khách hàng</strong></div>";

            s += "<div class=\"comment\">";
            var list = SupportService.Support_GetByAll(_lang);
            if (list.Count > 0)
            {
                foreach (var t in list)
                {
                    s += "<div class=\"support\">";

                    s += "<p><span class=\"namesp\">" + t.Name + ": </span><span class=\"phone\">" + t.Phone + "</span></p>\n";

                    //s += s += "<p><span class=\"namesp\">Email:</span><span class=\"phone\">" + t. + "</span></p>\n";

                    //yahoo
                    s += "<a href='ymsgr:sendim?" + t.NickYM + "' mce_href='ymsgr:sendim?" + t.NickYM + "'>";
                    s += "<img src='http://opi.yahoo.com/online?u=" + t.NickYM + "&t=2' mce_src='http://opi.yahoo.com/online?u=" + t.NickYM + "&t=1'></a>\n";

                    //skype
                    s += "<a href='skype:" + t.NickSkpye + "?call' onclick='return skypeCheck();'>";
                    s += "<img src='http://mystatus.skype.com/bigclassic/" + t.NickSkpye + "' style='border: none;' /></a>\n";

                    s += "</div>\n";
                }
            }
            s += "</div></div>\n";
            ltrSupport.Text = s;
            #region html code
            /*
             <div class="boxRightTittle">
                <div class="boxMenu">
                    <strong>Tư vấn và hỗ trợ khách hàng</strong></div>
                <div class="comment">
                    <div class="support">
                        <p><span class="namesp">Kinh doanh 1: </span><span class="phone">0989 898 898</span></p>
                        <a href="ymsgr:sendim?hiepprogrammer" mce_href="ymsgr:sendim?hiepprogrammer">
                            <img src="http://opi.yahoo.com/online?u=hiepprogrammer&t=2" mce_src="http://opi.yahoo.com/online?u=hiepprogrammer&t=1"></a>
                        <a href="skype:hiepprogrammer?call" onclick="return skypeCheck();">
                            <img src="http://mystatus.skype.com/bigclassic/hiepprogrammer" style="border: none;" /></a>
                    </div>
                    <div class="support">
                        <p>
                            <span class="namesp">Kinh doanh 1: </span><span class="phone">0989 898 898</span></p>
                        <a href="ymsgr:sendim?hiepprogrammer" mce_href="ymsgr:sendim?hiepprogrammer">
                            <img src="http://opi.yahoo.com/online?u=hiepprogrammer&t=2" mce_src="http://opi.yahoo.com/online?u=hiepprogrammer&t=1"></a>
                        <a href="skype:hiepprogrammer?call" onclick="return skypeCheck();">
                            <img src="http://mystatus.skype.com/bigclassic/hiepprogrammer" style="border: none;" /></a>
                    </div>
                </div>
            </div>
             */
            #endregion
        }
        #endregion

        #region Tuyen dung
        private void ShowTuyenDung()
        {
            var s = "";
            var list = AdvertiseService.Advertise_GetByTop("", "Active = '1' and Position = '7'", "[Ord] desc");
            if (list.Count > 0)
            {
                foreach (var t in list)
                {
                    s += "<div class=\"boxRightTD\">";
                    string path = t.Images;
                    if (path.IndexOf(".swf") > 0)
                    {
                        s += "<script language='javascript'>playfile('" + path + "', '" + t.Width + "', '" + t.Height + "', true, '', '', 'link=" + t.Link + "');</script>";
                    }
                    else
                    {
                        s += "<a href=\"" + t.Link + "\" target='" + t.Target + "'><img src='" + path + "' runat='server' style='border:0px' width='" + t.Width + "' height='" + t.Height + "' /></a>";
                    }
                    s += "</div>";
                }
                //ltrtuyendung.Text = s;
            }
            else
            {
                //ltrtuyendung.Text = "";
            }
            #region html code
            /*
             <div class="boxRightTD">
                    <script type="text/javascript">                playfile('/images/Banner_Tuyen_dung_nhan_su.swf', "286", "140", "false", "", "", "")</script>
                </div>
             */
            #endregion
        }
        #endregion

        #region Facebook
        private void ShowFacePage()
        {
            var s = "";
            var list = ConfigService.Config_GetById("1");
            if (list.Count > 0)
            {
                s += "<div class=\"boxFace\">";

                s += "<div class=\"fb-like-box\" data-href='" + list[0].Facebook + "' data-width='288'";
                s += "data-show-faces='true' data-stream='false' data-header='true'></div>";

                s += "</div>";
                ltrFacePage.Text = s;
            }
            #region html code
            /*
             <div class="boxFace">
                    <div class="fb-like-box" data-href="http://www.facebook.com/website24h" data-width="288"
                        data-show-faces="true" data-stream="false" data-header="true">
                    </div>
                </div>
             */
            #endregion
        }
        #endregion

        #region Position Company
        private void Vitri()
        {
            var s = "";
            var list = ConfigService.Config_GetById("1");
            if (list.Count > 0)
            {
                s += "<div class=\"boxRight\">";
                s += "<div class=\"boxRightTittle\"><div class=\"boxMenu\"><strong>Vị trí công ty</strong></div></div>";

                s += "<div class=\"comment fix\">";
                s += list[0].GoogleId;
                s += "</div>";

                s += "</div>";
                ltrVitri.Text = s;
            }
            #region html code
            /*
             <div class="boxRight">
                    <div class="boxRightTittle"><div class="boxMenu"><strong>Vị trí công ty</strong></div>
                    </div>
                    <div class="comment fix">
                        <iframe width="289" height="240" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=vi&amp;geocode=&amp;q=biztech,+H%C3%A0+N%E1%BB%99i,+Vi%E1%BB%87t+Nam&amp;aq=&amp;sll=37.0625,-95.677068&amp;sspn=39.371738,86.572266&amp;ie=UTF8&amp;hq=biztech,&amp;hnear=H%C3%A0+N%E1%BB%99i,+Ho%C3%A0n+Ki%E1%BA%BFm,+H%C3%A0+N%E1%BB%99i,+Vi%E1%BB%87t+Nam&amp;ll=21.046304,105.786227&amp;spn=0.090838,0.169086&amp;t=m&amp;z=13&amp;iwloc=A&amp;cid=9756879950362337507&amp;output=embed"></iframe><br /><small><a href="https://maps.google.com/maps?f=q&amp;source=embed&amp;hl=vi&amp;geocode=&amp;q=biztech,+H%C3%A0+N%E1%BB%99i,+Vi%E1%BB%87t+Nam&amp;aq=&amp;sll=37.0625,-95.677068&amp;sspn=39.371738,86.572266&amp;ie=UTF8&amp;hq=biztech,&amp;hnear=H%C3%A0+N%E1%BB%99i,+Ho%C3%A0n+Ki%E1%BA%BFm,+H%C3%A0+N%E1%BB%99i,+Vi%E1%BB%87t+Nam&amp;ll=21.046304,105.786227&amp;spn=0.090838,0.169086&amp;t=m&amp;z=13&amp;iwloc=A&amp;cid=9756879950362337507" style="color:#0000FF;text-align:left">Xem Bản đồ cỡ lớn hơn</a></small>
                    </div>
                </div>
             */
            #endregion
        }
        #endregion

        #region weather
        private void BindDropDownList()
        {
            ddlWeather.Items.Clear();
            ddlWeather.Items.Add(new ListItem("Sơn La", "SonLa"));
            ddlWeather.Items.Add(new ListItem("Hải phòng", "Haiphong"));
            ddlWeather.Items.Add(new ListItem("Hà Nội", "Hanoi"));
            ddlWeather.Items.Add(new ListItem("Vinh", "Vinh"));
            ddlWeather.Items.Add(new ListItem("Đà Nẵng", "Danang"));
            ddlWeather.Items.Add(new ListItem("Nha Trang", "Nhatrang"));
            ddlWeather.Items.Add(new ListItem("Pleiku", "Pleicu"));
            ddlWeather.Items.Add(new ListItem("Tp HCM", "HCM"));
            ddlWeather.Items.Add(new ListItem("Việt Trì", "Viettri"));
        }

        public string GetWeather(string City)
        {
            string strWrite = "";
            XmlTextReader reader = null;
            try
            {
                string AdImg = "";
                string AdImg1 = "";
                string AdImg2 = "";
                string Weather = "";

                reader = new XmlTextReader("http://vnexpress.net/ListFile/Weather/" + City + ".xml");
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(reader);

                XmlNodeList nodelist = xmldoc.SelectNodes("Item");
                XmlNode nodedetail;
                nodedetail = nodelist.Item(0).SelectSingleNode("AdImg");
                AdImg = nodedetail.InnerText;
                nodedetail = nodelist.Item(0).SelectSingleNode("AdImg1");
                AdImg1 = nodedetail.InnerText;
                nodedetail = nodelist.Item(0).SelectSingleNode("AdImg2");
                AdImg2 = nodedetail.InnerText;
                nodedetail = nodelist.Item(0).SelectSingleNode("Weather");
                Weather = nodedetail.InnerText;

                strWrite += "<img src='http://vnexpress.net/Images/Weather/" + AdImg + "' border='0' width='36' height='35' />&nbsp;";
                strWrite += "<img src='http://vnexpress.net/Images/Weather/" + AdImg1 + "' border='0' width='19' height='28' />";
                strWrite += "<img src='http://vnexpress.net/Images/Weather/" + AdImg2 + "' border='0' width='19' height='28' />";
                strWrite += "<img src='http://vnexpress.net/Images/Weather/c.gif' width='35' height='28' /><br />";
                strWrite += Weather;
            }
            catch (Exception ex)
            {
                strWrite = ex.Message;
            }
            finally
            {
                reader.Close();
            }
            return strWrite;
        }

        protected void ddlWeather_SelectedIndexChanged(object sender, EventArgs e)
        {
            divWeather.InnerHtml = GetWeather(ddlWeather.SelectedValue);
        }
        #endregion

        #region Ty gia

        #endregion

        #region Load Gio hang
        protected void LoadCard()
        {
            int num = 0;
            float price = 0;
            if (Session["Card"] != null)
            {
                DataTable dt = (DataTable)Session["Card"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        num += int.Parse(dt.Rows[i]["Quantity"].ToString());
                        price += int.Parse(dt.Rows[i]["Price"].ToString());
                    }
                }
                ltrcart.Text = "<li>Số lượng : " + num + "</li><li>" + Session["TotalPrice"] + " VND </li>";
            }
            else
            {
                ltrcart.Text = "<li>Giỏ hàng rỗng !</li><li></li>";
            }
        }

        #endregion

        #region cart
        protected void lbtviews_Click(object sender, EventArgs e)
        {
            Response.Redirect("gio-hang.html");
        }

        protected void lbtBuy_Click(object sender, EventArgs e)
        {

        }
        #endregion
    }
}